<template>
  <div>
    <p>concat</p>
    <p>fill</p>
    <p>find,findIndex</p>
    <p>join</p>
    <p>lastIndexOf</p>
    <p>pop</p>
    <p>reduce</p>
    <p>slice</p>
    <p>some</p>
    <p>sort</p>
    <p>splice</p>
    <p>unshift</p>
  </div>
</template>

<script >
export default {
  name: "arrayFn",
  data() {
    return {};
  },
  mounted() {
    let a = [1, 2, 3];
    let b = [3, 4, 5];
    let c = [4, 5];
    let d = a.concat(a, b, c);
    console.log(d);
    console.log(d.lastIndexOf(5)); //相同时寻找元素最后一个下标

    let array9 = Array(9).fill("");
    console.log(array9);
    a.find((item) => {
      item == 1;
    });
    console.log(
      a.find((item) => {
        return item == 1;
      })
    );
    console.log(
      a.findIndex((item) => {
        return item == 1;
      })
    );

    console.log(Array.isArray({ a: [123] })); //false

    console.log(a.join());
    console.log(a.join("-"));

    var fruits = ["Banana", "Orange", "Apple", "Mango"];
    // console.log(fruits.reverse());翻转数组会改变原数组
    console.log(fruits.pop());  //返回是删除的元素 改变了原数组
    console.log(fruits);
    console.log(fruits.shift());
    console.log(fruits);
    var numbers = [15.5, 2.3, 1.1, 4.7];

    console.log(
      numbers.reduce((total, num) => {
        console.log(Math.round(num));
        return total + Math.round(num); //四舍五入后求总值
      })
    );

    var arr2 = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
    var citrus = arr2.slice(1, 3);
    console.log(citrus); //从何处开始选取到处结束，不包含结束处   不会改变原始数组

    var ages = [3, 10, 18, 20];
    console.log(
      ages.some((age) => {
        return age >= 18;
      })
    ); //返回true 检测数组中是否有元素大于 18  不会改变原始数组

    var so = [1, 32, 23, 4];
    so.sort(); //会改变原数组
    console.log(so);

    var points = [40, 100, 1, 5, 25, 10];
    points.sort(function (a, b) {
      return a - b;
    }); //数字升序
    points.sort(function (a, b) {
      return b - a;
    }); //数字降序

    var arr3 = ["Banana", "Orange", "Apple", "Mango"];
    // arr3.splice(2, 0, "Lemon", "Kiwi");   //第一个参数是下标，第二个参数是要删除的个数，第三四是要添加的元素
    // console.log(arr3);  //Banana,Orange,Lemon,Kiwi,Apple,Mango
    // arr3.splice(2, 0);
    // console.log(arr3); //删除0个
    arr3.splice(2);
    console.log(arr3); //删除下标2之后的 

    var arr4 = ["Banana", "Orange", "Apple", "Mango"];
    console.log(arr4.toString());  //把数组转换为字符串，并返回结果。

    arr4.unshift("Lemon","Pineapple");
    console.log(arr4);
    arr4.push("Lemon","Pineapple");
    console.log(arr4)


    let arr5=[{a:1,b:2},{a:3,b:4}]
    const arrMap=arr5.map(item=>{
        return item.a
    })
    console.log(arrMap);
  },
  methods: {},
};
</script>

<style scoped>
p {
  text-align: center;
}
</style>
